package com.stx.design.prototype;

import java.util.Hashtable;

public class ShapeCache {
	
	public static final String TYPE_CICLE = "1";
	public static final String TYPE_SQUARE = "2";
	public static final String TYPE_RECTANGLE = "3";
	
	private static Hashtable<String, Shape> shapeMap = new Hashtable<String, Shape>();
	
	public static Shape getShape(String shapeId){
		if(TYPE_CICLE.equals(shapeId) || 
			TYPE_SQUARE.equals(shapeId) || 
			TYPE_RECTANGLE.equals(TYPE_RECTANGLE)){
		}else{
			System.out.print("not support type: " + shapeId);
			return null;
		}
		Shape shape = shapeMap.get(shapeId);
		if(shape == null){
			System.out.print("has not init shape...");
			return null;
		}
		return (Shape)shape.clone();
	}
	
	   public static void loadCache() {
	      Circle circle = new Circle();
	      circle.setId(TYPE_CICLE);
	      circle.setType("Circle");
	      shapeMap.put(circle.getId(),circle);
	 
	      Square square = new Square();
	      square.setId(TYPE_SQUARE);
	      square.setType("Square");
	      shapeMap.put(square.getId(),square);
	 
	      Rectangle rectangle = new Rectangle();
	      rectangle.setId(TYPE_RECTANGLE);
	      rectangle.setType("Rectangle");
	      shapeMap.put(rectangle.getId(),rectangle);
	   }
	   
}




